A Novel Angle Segmentation Method for Magnetic Encoders Based on Filtering Window Adaptive Adjustment Using Improved Particle Swarm Optimization

In this paper we outline newly-developed control algorithms, designed to achieve high-precision feedback for a motor control system using a magnetic encoder. The magnetic encoder, combing single-pole and multi-pole magnetic steels, was adopted to extend the resolution of the magnetic encoder. First, with a view to settling the issue of the jump points of the multi-pole angle value at the convergence of two adjacent magnetic poles, the angle segmentation method, which uses the window filter discrimination method, is employed to determine the actual angle value. The appropriate filter window width is selected via the improved particle swarm optimization (IPSO) algorithm, and an expanded resolution is achieved. Second, a compensation table is completed via a linear compensation algorithm based on virtual cutting to enhance the accuracy of the combined magnetic encoder. On this basis, a linear difference algorithm is used to achieve deviation correction of the angle. Finally, the jump points can be restrained effectively via the angle segmentation method. The resolution reaches 0.05°, and the accuracy is 0.045°.


Introduction
As industrialization moves further towards high-end manufacturing, the applications of permanent magnet synchronous motor (PMSM) drives increase, especially in the field of servo drive [1,2].
Aiming at improving PMSM control precision and response speed, on the one hand, the control strategy with high performance of the motor is examined here.An optimized control based on Proportional-Integral-Derivative (PID) control is proposed, which can address the adverse effects caused by low-cost magnetic encoders, thus improving the control performance and precision of PMSM [3].A multi-motor synchronization control is emphasized in [4], ensuring the stability and robustness of the control system in the presence of external disturbances.On the other hand, improving the precision and accuracy of encoders, the feedback element of the control system offers another approach to enhancing the control precision of the control system [5].Among numerous encoders, rotary encoders are widely applied [6][7][8] and photoelectric encoders and magnetic encoders are the most common.Although the photoelectric encoder has high detection accuracy, the volume it requires increases with higher accuracy, and it cannot be used in harsh environments with pollution, vibration, and other factors [9,10].Despite these shortcomings, magnetic encoders are increasingly needed.
Many types of research have been conducted on the structure and algorithm in terms of the issue of inferior accuracy and poor resolution for the magnetic encoder [10] its structure, these issues can be alleviated by improving the installation accuracy of the Hall elements, the direction and accuracy of magnetization of the magnetic steel, and the number of poles contained in the magnetic steel.An eccentric rotation structure is employed to obtain high resolution without reducing absolute angle precision in [10][11][12].However, the method of handling multi-poles is not related to the number of Hall ICs that fail, as pointed out in [10], and long short-term memory (LSTM) has been proposed in [11] to decrease the huge angular position error when the number of sensors is cut down.An absolute multi-pole structure including an index track and sub-division track has been proposed to enhance the resolution of the encoder [13].The accuracy of a special magnetic medium can be enhanced when it is modified and flattened.Thus, a linear magnetic encoder requires high position precision [14].
Regarding software algorithms, a rotary magnetic encoder that adopts a novel sensing mechanism was proposed in [7].Time pulses, a measurement basis, are recorded to compute the angular position.Finally, high resolution and stability are obtained.Aiming to increase the precision of a multi-turn absolute magnetic encoder with the feature of being battery-free, a high-resolution, self-referencing lookup table (LUT) algorithm has been presented in which bipolar magnet (BPM) signals are used to introduce the tables for multi-turn angles, eliminating the external disturbance effects of the BPM signals [15].An efficient error correction algorithm, which is designed for magnetic analog encoders (MAEs), requires very little memory space compared with the LUT.When this is combined with a type-2 phase-locked loop (PLL), a ±0.2 • total position error can be obtained [16].An adaptive linear neuron algorithm has been proposed that is based on a third-order PLL.It compensates sinusoidal and cosine signals for the magnetic encoder and eliminates noise and DC error in the phase as well as frequency steps.The simulation and experimental results demonstrate that the method can enhance the precision of the absolute magnetic encoder [17].In ref. [18], a digital phase-locked loop (AADPLL) compensating the noisy signals of the magnetic encoder by assisting with a pulse interpolator achieved the maximum operating speed and the highest resolution.Moreover, intelligent algorithms such as a neural network [12,19] and fuzzy algorithm [20] have also been used to enhance the accuracy and resolution of magnetic encoders.In ref. [12], a neural network was combined with eccentric rotation to solve the issue of absolute angle calculation.A radial basis function neural network (RBFNN) has been proposed and added to the PLL to prevent disturbances of quadrature sinusoidal signals, thus improving the accuracy of the magnetic encoder [19].To achieve high-precision control, a multi-sensor data fusion methodology has been proposed in which fuzzy logic is introduced.Moreover, it introduces a projected electronic circuit to analogically implement the Takagi-Sugeno model, which maintains the signal uninterruptedly and naturally [20].To enhance the position resolution, position interpolation has been put forward in which the sine and cosine signals of every two incremental encoders are collected [21].A listing of classical methods and their features is given in Table 1.
Table 1.Several classical technologies to improve the precision and resolution.

Reference
Technologies Merits [11] Long Short-Term Memory (LSTM) Decreasing angle error via fewer sensors [15] Self-referencing lookup table (LUT) Eliminating the external disturbance effects [16] Type-2 phase-locked loop (PLL) Using little memory, with total position error of ±0.2 • [17] Adaptive Linear-Neuron and a third-order phase-locked loop (ALN-PLL) Reducing noise and eliminating dc-error, and rejecting the disturbances [18] Digital phase-locked loop (AADPLL) Extracting high-order sinusoids Most of the studies above have enhanced the resolution and accuracy of magnetic encoders without considering the changes in the environment.Therefore, the magnetic Sensors 2023, 23, 8695 3 of 18 sensitivity coefficient of the encoder changes as the ambient conditions vary, causing the appearance of jump points in the angle solution when the magnetic encoder is at the convergence of two adjacent magnetic poles.At exactly that moment, the current pole number of the magnetic encoder fails to be distinguished.Thus, improving its accuracy and resolution maintains an unsolved problem.In this paper, a window-filtering algorithm using the front window, present window, and back window is applied to determine the number of poles that the encoder is currently located in.However, jump points occur when a poor window width is chosen.
The search space for the proper window width is viewed as the flight space of birds, in which each bird is abstracted as a particle representing a feasible solution of the window width.Thus, the window size of the optimization problem is equivalent to the food source that the birds are looking for.This algorithm is called particle swarm optimization (PSO).At present, various optimization problems such as multimodal problems [22], the optimal charge pattern of Li-ion batteries [23], thinned planar array design [24], and mobile robot swarms [25] have been solved by PSO.In this article, the IPSO algorithm is employed to find the appropriate window width.On this basis, a window-filtering algorithm is applied to judge the pole number of the magnetic encoder, eliminating jump points under complex conditions.
The main contributions of this paper can be summarized as follows: (1) The window width is screened by a window-filtering angle subdivision algorithm with a dynamic inertia coefficient, which is used to judge the number of poles of the magnetic encoder for which local optimal solutions fail to occur.Hence, an accurate optimal solution can be obtained with fewer iterations, which boosts the operation speed, avoiding the appearance of jump points of the magnetic encoder caused by the error estimation of the window width.Meanwhile, the encoder resolution is improved after subdivision.(2) The accuracy of the magnetic encoder is enhanced by a linear interpolation compensation tabulation algorithm based on virtual cutting.The error compensation table is stored in the fixed memory area of the MCU, which can be retrieved in time as the servo control system works, and the compensation result remains stable and reliable.
Compared with cross-interval tabulation employed in the arctangent method [26], the compensation method based on virtual cutting enables the angle of the magnetic encoder to remain high.

Structure Design
The magnetic encoder in this paper combines two types of magnetic steel and includes six Hall elements, a signal acquisition board, a magnetic isolation ring, a magnetic conduction ring, and other components, and its structure is shown in Figure 1.
Most of the studies above have enhanced the resolution and accuracy of magnetic encoders without considering the changes in the environment.Therefore, the magnetic sensitivity coefficient of the encoder changes as the ambient conditions vary, causing the appearance of jump points in the angle solution when the magnetic encoder is at the convergence of two adjacent magnetic poles.At exactly that moment, the current pole number of the magnetic encoder fails to be distinguished.Thus, improving its accuracy and resolution maintains an unsolved problem.In this paper, a window-filtering algorithm using the front window, present window, and back window is applied to determine the number of poles that the encoder is currently located in.However, jump points occur when a poor window width is chosen.
The search space for the proper window width is viewed as the flight space of birds, in which each bird is abstracted as a particle representing a feasible solution of the window width.Thus, the window size of the optimization problem is equivalent to the food source that the birds are looking for.This algorithm is called particle swarm optimization (PSO).At present, various optimization problems such as multimodal problems [22], the optimal charge pattern of Li-ion batteries [23], thinned planar array design [24], and mobile robot swarms [25] have been solved by PSO.In this article, the IPSO algorithm is employed to find the appropriate window width.On this basis, a window-filtering algorithm is applied to judge the pole number of the magnetic encoder, eliminating jump points under complex conditions.
The main contributions of this paper can be summarized as follows: (1) The window width is screened by a window-filtering angle subdivision algorithm with a dynamic inertia coefficient, which is used to judge the number of poles of the magnetic encoder for which local optimal solutions fail to occur.Hence, an accurate optimal solution can be obtained with fewer iterations, which boosts the operation speed, avoiding the appearance of jump points of the magnetic encoder caused by the error estimation of the window width.Meanwhile, the encoder resolution is improved after subdivision.(2) The accuracy of the magnetic encoder is enhanced by a linear interpolation compensation tabulation algorithm based on virtual cutting.The error compensation table is stored in the fixed memory area of the MCU, which can be retrieved in time as the servo control system works, and the compensation result remains stable and reliable.
Compared with cross-interval tabulation employed in the arctangent method [26], the compensation method based on virtual cutting enables the angle of the magnetic encoder to remain high.

Structure Design
The magnetic encoder in this paper combines two types of magnetic steel and includes six Hall elements, a signal acquisition board, a magnetic isolation ring, a magnetic conduction ring, and other components, and its structure is shown in Figure 1.Multi-pole magnetic steel with axial magnetization that is radial serves as single-pole magnetic steel.In order to save space, the plug-in structure of the single-pole Hall element is used and is uniformly distributed on the circumference of the signal acquisition board.Surface-mounted Hall elements are selected as the multi-pole Hall elements.There are three multi-pole Hall elements that are arranged along the large radius with an angle of 120 • and three single-pole Hall elements that are distributed along the small radius collecting the Hall signal.The angle between multi-pole Hall elements is where p mul is the pole number, p mul = 24, k co f f is the adjustment coefficient of the hall angle,

Working Principle
The angle solution scheme is shown in Figure 2. When the spindle shaft of the motor rotates, two kinds of magnetic steel generate magnetic field signals separately.Meanwhile, the Hall elements that are installed on the signal acquisition board will induce a magnetic field signal, which will be converted into a three-phase sine or cosine voltage signal, and then converted into a two-phase voltage signal with a phase difference of 90 • .Finally, the angle values can be obtained from the arctangent of the digital signals, which the two-phase voltage is converted into through the analog-to-digital (AD) conversion module inside the microcontroller.Multi-pole magnetic steel with axial magnetization that is radial serves as single-pole magnetic steel.In order to save space, the plug-in structure of the single-pole Hall element is used and is uniformly distributed on the circumference of the signal acquisition board.Surface-mounted Hall elements are selected as the multi-pole Hall elements.There are three multi-pole Hall elements that are arranged along the large radius with an angle of 120° and three single-pole Hall elements that are distributed along the small radius collecting the Hall signal.The angle between multi-pole Hall elements is ( ) where mul p is the pole number, 24 is the adjustment coefficient of the hall angle,

Working Principle
The angle solution scheme is shown in Figure 2. When the spindle shaft of the motor rotates, two kinds of magnetic steel generate magnetic field signals separately.Meanwhile, the Hall elements that are installed on the signal acquisition board will induce a magnetic field signal, which will be converted into a three-phase sine or cosine voltage signal, and then converted into a two-phase voltage signal with a phase difference of 90°.Finally, the angle values can be obtained from the arctangent of the digital signals, which the two-phase voltage is converted into through the analog-to-digital (AD) conversion module inside the microcontroller.The appropriate filter window interval can be found via the IPSO algorithm.On the basis of this filtering window range, an angle subdivision method for the window filter is established to solve the jump problem of the magnetic encoder at the zero-crossing point.Then, a compensation algorithm based on virtual cutting is established to compensate for the resolution error.Finally, the angle value is input into the controller through a serial peripheral interface (SPI) to control the rotation of the motor.The appropriate filter window interval can be found via the IPSO algorithm.On the basis of this filtering window range, an angle subdivision method for the window filter is established to solve the jump problem of the magnetic encoder at the zero-crossing point.Then, a compensation algorithm based on virtual cutting is established to compensate for the resolution error.Finally, the angle value is input into the controller through a serial peripheral interface (SPI) to control the rotation of the motor.

The Window Filter Angle Value Division Method Based on the IPSO 3.1. The Angle Subdivision Method Based on the Window Filter
The output waveform of the single-pole and multi-pole angle values sampled by the data acquisition card is shown in Figure 3a.

The Angle Subdivision Method Based on the Window Filter
The output waveform of the single-pole and multi-pole angle values sampled by the data acquisition card is shown in Figure 3a.It may be observed from Figure 3a that jump points occur as the magnetic encoder crosses the two adjacent magnetic poles, leaving the pole number and the angle values undetermined.To solve this issue, two filter windows, those of the front and back layers, are built to judge the number of poles in this paper.
First, the zero point of two groups of angle values needs to be calibrated.The angle value of the single-pole angle is set as the reference to sort from small to large, and the multi-pole angle is moved accordingly.Hence, the calibration function is defined as The highest 11 bits of single-pole angle values are extracted, and the ordinal index of the maximum value is recorded successively from the values with the same highest 11 bits.This is given by where floor is the rounding function, It may be observed from Figure 3a that jump points occur as the magnetic encoder crosses the two adjacent magnetic poles, leaving the pole number and the angle values undetermined.To solve this issue, two filter windows, those of the front and back layers, are built to judge the number of poles in this paper.
First, the zero point of two groups of angle values needs to be calibrated.The angle value of the single-pole angle is set as the reference to sort from small to large, and the multi-pole angle is moved accordingly.Hence, the calibration function is defined as where θ s is the single-pole angle value obtained via sampling, θ m is the multi-pole angle value obtained by sampling, θ s_x is the sorted single-pole angle value, and θ m_y is the sorted multi-pole angle value.The sorted angle resolution waveform is shown in Figure 3b.The highest 11 bits of single-pole angle values are extracted, and the ordinal index of the maximum value is recorded successively from the values with the same highest 11 bits.This is given by where f loor is the rounding function, f end is the filtering function, and h note is the recording function.θ s_sel_x is the set of highest 11-bit single-pole angle values selected, and j s_note is the rearrangement of the serial number of the maximum value from the serial numbers of the values with the same highest 11 bits.The serial numbers are divided into three intervals, namely S1 = [0, 4096), S2 = [4096, 61,440), and S3 = [61,440, 65,536).The multi-pole angle values are extracted one by one according to the serial numbers and treated as a basis for the lookup table.The distribution of angle values after interval division is shown in Figure 4. .
When the differences between the two adjacent angles of each layer window with the threshold value 30,000 are compared, the pole numbers related to the angle value in each layer window above are determined.
The angle value of each layer window is substituted into Equation (5) as input: The pole number of the front window, current window, and back window, which are expressed by Equation ( 4) shows the filter windows of the front, current and back layers, which are set to judge the number of poles.
where θ M back arry is the back boundary of the window area, θ M f ront arry is the front boundary of the window area, and x window is window size satisfying x window ∈ (0, 65, 535).
When the differences between the two adjacent angles of each layer window with the threshold value 30,000 are compared, the pole numbers related to the angle value in each layer window above are determined.
The angle value of each layer window is substituted into Equation (5) as input: The pole number of the front window, current window, and back window, which are expressed by P f ront M , P curr M , and P back M , can be obtained.The schematic diagram of the pole number distribution is shown in Figure 5.
according to the serial numbers and treated as a basis for the lookup table.The distribution of angle values after interval division is shown in Figure 4. Equation ( 4) shows the filter windows of the front, current and back layers, which are set to judge the number of poles. .
When the differences between the two adjacent angles of each layer window with the threshold value 30,000 are compared, the pole numbers related to the angle value in each layer window above are determined.
The angle value of each layer window is substituted into Equation (5) as input: The pole number and the angle interval in each three-layer window can be checked using the highest 11 bits of the single-pole angle value, assuming that the window width is set appropriately: where check is the table lookup function, θ S_act(k) is the single-pole angle value, p M_x (k) is the pole number obtained using the lookup table, and θ M_act(k) is the multi-pole angle value obtained using the lookup table.There exist two cases in which the pole number is misjudged.One case is that the pole number of the front-layer window is greater than that of the current window, but the angle value is located in S1, as shown in Figure 6a.At the same time, Figure 6b illustrates the other case that the pole number of the back-layer window is less than that of the current window, but the angle value stays in S3.The pole number and the angle interval in each three-layer window can be checke using the highest 11 bits of the single-pole angle value, assuming that the window wid is set appropriately: where check is the table lookup function, is the single-pole angle value, _ ( ) M x k p the pole number obtained using the lookup table, and  is the multi-pole ang value obtained using the lookup table.There exist two cases in which the pole number is misjudged.One case is that th pole number of the front-layer window is greater than that of the current window, but th angle value is located in S1, as shown in Figure 6a.At the same time, Figure 6b illustrat the other case that the pole number of the back-layer window is less than that of the cu rent window, but the angle value stays in S3.The servo control system is still capable of calculating the pole number of the ma netic encoder by referring to the above method.Then, the multi-pole angle value aft segmentation can be expressed as


is the multi-pole angle value when the segmentation algorithm is employe

The Filtering Window Width Prediction Algorithm Based on IPSO
Figure 5 above is just a schematic of the pole number for the three-layer windo under ideal conditions without determination of the window width.If the window size not selected appropriately, new jump points will be introduced.Therefore, in this pape the IPSO algorithm is adopted in the segmentation algorithm to determine the approp ate filter window interval, making the angle value after the segmentation prevent the e istence of jump points.This method remains capable of resolving the issue of jump poin in the decoding process of magnetic encoders with different pole numbers, which prov efficient and simple.
The function of the IPSO algorithm is to calculate the window width according to The servo control system is still capable of calculating the pole number of the magnetic encoder by referring to the above method.Then, the multi-pole angle value after segmentation can be expressed as where θ M_div is the multi-pole angle value when the segmentation algorithm is employed.

The Filtering Window Width Prediction Algorithm Based on IPSO
Figure 5 above is just a schematic of the pole number for the three-layer window under ideal conditions without determination of the window width.If the window size is not selected appropriately, new jump points will be introduced.Therefore, in this paper, the IPSO algorithm is adopted in the segmentation algorithm to determine the appropriate filter window interval, making the angle value after the segmentation prevent the existence of jump points.This method remains capable of resolving the issue of jump points in the decoding process of magnetic encoders with different pole numbers, which proves efficient and simple.
The function of the IPSO algorithm is to calculate the window width according to where y jump_point is the number of jump points of the multi-pole angle after segmentation, and θ M_div_err is the difference in multi-pole angle after segmentation.
Sensors 2023, 23, 8695 8 of 18 The inertia weight factor in Equation ( 9) effectively prevents the occurrence of a local optimal solution of the window width selection: where ω is the inertia weight factor, i ger is the number of iterations, ω init is the initialization weight, ω max is the maximum weight value, and T ger is the maximum number of iterations.Each particle in the swarm represents a practical strategy, and its position and velocity are continuously updated as iterations increase: The global optimal part (10) where r 1 and r 2 are decimals on the interval [0, 1], p id is the individual optimal particle position obtained, p gd is the global optimal particle position acquired, c 1 is an individual learning factor, c 2 is a global learning factor, and x is the particle position.
A pole number prediction method, based on the filtering window width obtained via the IPSO algorithm above, is established to solve the issue of multi-pole angle hopping caused by environmental changes and other factors.
The difference in multi-pole angle after subdivision is Substituting this into Equation (8) gives the objective function as The population is initialized with the number of iterations of the swarm set as 100 and the number of particles in the swarm set as 30.The individual fitness and population fitness are updated as iterations increase, and the speed and position are updated according to Equations (10) and (11).The specific process is shown in Figure 7.
The PSO algorithm with dynamic inertia weight coefficient is adopted according to Equation (9).The values of ω init , ω max , and T ger are set as 0.4, 0.9, and 100, respectively.The distribution of inertia weight is shown in Figure 8.
It can be seen that ω stays large at the start of the iteration, which facilitates global searching.However, the inertia coefficient in the later stage of the iteration remains small, facilitating a local search within a certain range, which favors finding the optimal solution accurately and reducing the search time.
The window width is determined using the IPSO algorithm.The distribution of the initialized particle state is exhibited in Figure 9a, and the distribution of the particle state after optimization is shown in Figure 9b.The calculated window width is 24,454, and the optimal fitness namely the number of jump points after subdivision is 0, indicating that there is no jump point and the selected window value is appropriate.
When the single-increment try out method is used to select the window width and the trial step size is 1, the calculation of data in the process is tremendous and there remains an extraordinarily long runtime.The magnetic encoder has a pole number of 24, resulting in numerous window widths that satisfy the condition.The distribution of window width using a single-increment try-out method is shown in Figure 9a,b.It is evident that the selected window widths, producing the angle value, leads to the presence of jump points at I, II, III, IV, V, and VI, indicating that these window widths are unreasonable.The greater the pole number of the magnetic encoder is, the less the suitable window width.In order to reduce computational load, longer step sizes, such as 1000 and 2000, are adopted in the single-increment try-out method, which may result in the complete absence of all reasonable window widths.
Substituting the window width obtained via the IPSO algorithm into Equations ( 4) and ( 5) results in the final tabulation of the multi-pole angle interval and pole number, as shown in Figure 10.

Start
Population initialization: c1=0.6,c2=0.6,N=30,ger=100 )  The window width is determined using the IPSO algorithm.The distribution of the initialized particle state is exhibited in Figure 9a, and the distribution of the particle state after optimization is shown in Figure 9b.The calculated window width is 24,454, and the optimal fitness namely the number of jump points after subdivision is 0, indicating that there is no jump point and the selected window value is appropriate.The window width is determined using the IPSO algorithm.T initialized particle state is exhibited in Figure 9a, and the distributio after optimization is shown in Figure 9b.The calculated window w initialized particle state is exhibited in Figure 9a, and the distribution of the particl after optimization is shown in Figure 9b.The calculated window width is 24,454, a optimal fitness namely the number of jump points after subdivision is 0, indicatin there is no jump point and the selected window value is appropriate.dow width using a single-increment try-out method is shown in Figure 9a,b that the selected window widths, producing the angle value, leads to the pre points at I, II, III, IV, V, and VI, indicating that these window widths are u The greater the pole number of the magnetic encoder is, the less the suit width.In order to reduce computational load, longer step sizes, such as 1000 adopted in the single-increment try-out method, which may result in the sence of all reasonable window widths.Substituting the window width obtained via the IPSO algorithm into and ( 5) results in the final tabulation of the multi-pole angle interval and po shown in Figure 10.
Figure 11 shows the flow chart of the angle segmentation method based o the searching process for the window width in Figure 7 is added to the identifi for the pole number.For the two special cases in which the magnetic encode in Figure 6a,b, the pole number in the first case is regarded as the current pole 1, and in the second case, it is considered as the current pole number minus can be determined from the final lookup table shown in Figure 10, according pole angle value of the highest 11 bits (0-2047) in the servo control system.Figure 11 shows the flow chart of the angle segmentation method based on IPSO when the searching process for the window width in Figure 7 is added to the identification process for the pole number.For the two special cases in which the magnetic encoder crosses zero in Figure 6a,b, the pole number in the first case is regarded as the current pole number plus 1, and in the second case, it is considered as the current pole number minus 1.Thus, θ M_div can be determined from the final lookup table shown in Figure 10, according to the single-pole angle value of the highest 11 bits (0-2047) in the servo control system.
The multi-pole angle resolution is obtained by substituting the calculated pole number into Equation (7) and is shown in Figure 12.It can be seen that there is no jump point after subdivision, and the resolution of the angle values is increased from 2 16 LSB to 3 × 2 19 LSB.

Start
The PSO algorithm is used to search the suitable filter window width.(Fig.7)

The Angle value interval and the number of poles are tabulated：
The angle value of the higher 11 bits are obtained.Then, the pole number of the three layer windows and the interval of multi-pole angle values are found out by look-up table method.
The 11 bits higher of single angle value are set as the abscissa.
The number of the poles of the front window, the current window, and the back window are taken as the ordinate.
The multi-pole angle values are divided into three intervals.The multi-pole angle resolution is obtained by substituting the calculated pole nu ber into Equation (7) and is shown in Figure 12.It can be seen that there is no jump po after subdivision, and the resolution of the angle values is increased from 16 2 LSB to 3 LSB.

The original angle value
The subdivided angle value

Linear Interpolation Compensation Tabulation Method Based on Virtual Cutting
The resolution of the novel magnetic encoder is enhanced by the segmentat method proposed in Section 3, but its accuracy remains inferior.Therefore, the photoe tric encoder, which is installed coaxially with the combined encoder, is used to lower error of the combined magnetic encoder.The PSO algorithm is used to search the suitable filter window width.(Fig.7) The Angle value interval and the number of poles are tabulated： and the interval of multi-pole angle values are found out by look-up table method.
The 11 bits higher of single angle value are set as the abscissa.
The number of the poles of the front window, the current window, and the back window are taken as the ordinate.
The The multi-pole angle resolution is obtained by substituting the calculated pole ber into Equation ( 7) and is shown in Figure 12.It can be seen that there is no jump after subdivision, and the resolution of the angle values is increased from 16  2 LSB to LSB.

The original angle value
The subdivided angle value

Linear Interpolation Compensation Tabulation Method Based on Virtual Cutti
The resolution of the novel magnetic encoder is enhanced by the segmen method proposed in Section 3, but its accuracy remains inferior.Therefore, the phot tric encoder, which is installed coaxially with the combined encoder, is used to low error of the combined magnetic encoder.

Linear Interpolation Compensation Tabulation Method Based on Virtual Cutting
The resolution of the novel magnetic encoder is enhanced by the segmentation method proposed in Section 3, but its accuracy remains inferior.Therefore, the photoelectric encoder, which is installed coaxially with the combined encoder, is used to lower the error of the combined magnetic encoder.
The angle deviation between the photoelectric encoder and magnetic encoder can be expressed as θ M_Gd_err = θ Gd − θ M_div (14) where θ Gd is the angle value of the photoelectric encoder, and θ M_Gd_err is the angle deviation between the photoelectric encoder and the magnetic encoder.
Then, the angle values of the combined encoder are sorted from small to large and are shrunk by a factor of 2 6 /5.Meanwhile, the angle deviation of the two types of encoders changes accordingly.The formula is 65,536 where θ M_div_xx is the sorted angle value of the magnetic encoder, and θ M_Gd_err_yy is the sorted angle deviation of the two types of encoders.
The angle deviation compensation table obtained by the cross-interval tabulation method [26] is shown in Figure 13a,b and shows the differential value of each point.What seems self-evident is that there remains a lot of high-frequency noise in Figure 13a, which is represented by the differential value of each point in Figure 13b.This introduces highfrequency oscillation in the angle if the compensation table in Figure 13a is utilized directly.Thus, this issue can be solved by linear interpolation compensation tabulation based on virtual cutting, the core idea of which is oversampling.
The angle deviation between the photoelectric encoder and magnetic encoder can be expressed as

= −
M_Gd_err Gd M_div θ θ θ (14) where Gd θ is the angle value of the photoelectric encoder, and M_Gd_err θ is the angle deviation between the photoelectric encoder and the magnetic encoder.Then, the angle values of the combined encoder are sorted from small to large and are shrunk by a factor of 6  25 .Meanwhile, the angle deviation of the two types of encoders changes accordingly.The formula is 10 () 25 65536 () where M_div_xx θ is the sorted angle value of the magnetic encoder, and M_Gd_err_yy θ is the sorted angle deviation of the two types of encoders.The angle deviation compensation table obtained by the cross-interval tabulation method [26] is shown in Figure 13a,b and shows the differential value of each point.What seems self-evident is that there remains a lot of high-frequency noise in Figure 13a, which is represented by the differential value of each point in Figure 13b.This introduces highfrequency oscillation in the angle if the compensation table in Figure 13a is utilized directly.Thus, this issue can be solved by linear interpolation compensation tabulation based on virtual cutting, the core idea of which is oversampling.According to oversampling theory [27], a 1-bit accuracy improvement is gained through the utilization of an AD converter, with each 4-bit increase in the ratio of oversampling.
A moving average algorithm is employed to realize oversampling interpolation in the microcontroller.The angle value in Equation ( 15) has been reduced to the interval, correspondingly, resulting in the cutting of the angle value of the magnetic encoder, presented in Figure 14.According to oversampling theory [27], a 1-bit accuracy improvement is gained through the utilization of an AD converter, with each 4-bit increase in the ratio of oversampling.
A moving average algorithm is employed to realize oversampling interpolation in the microcontroller.The angle value in Equation (15) has been reduced to the interval, [0, 5 × 2 10 ).The virtual step C stair obtains an increase of 1LSB for every 1LSB increase in the angle value.At the same time, C p (i) is used to record the coordinates of the sampling point of the angle value for each C stair correspondingly, resulting in the cutting of the angle value of the magnetic encoder, as presented in Figure 14.
Region I in Figure 14 displays the result of the angle cutting.The angle values contained in the last four steps in region I are spliced into the first section, and the initial four steps are stitched to the end.Therefore, the total number of virtual steps is 5128.
The moving average is calculated for the angle values at each of the four steps from position C p (1) at the time at which the virtual cutting of the sampling points is completed: Sensors 2023, 23, 8695 13 of 18 where θ M_aver is the average angle value of the magnetic encoder in every four steps, θ err_aver is the average angle error of the two types of encoders installed coaxially in every four steps, and i is the sampling point.Region I in Figure 14 displays the result of the angle cutting.The angle values c tained in the last four steps in region I are spliced into the first section, and the initial f steps are stitched to the end.Therefore, the total number of virtual steps is 5128.
The moving average is calculated for the angle values at each of the four steps fr position ( ) at the time at which the virtual cutting of the sampling points is c pleted: Since the linear fitting calculation is completed, virtual lines are constructed ev four sampling points, which is shown in Equation (18).The angle error of the samp point before the four sampling points is calculated by this line.Then, the error compen tion table calculated from Equation ( 18) is obtained and stored in the internal mem unit of the single-chip microcomputer.Since the linear fitting calculation is completed, virtual lines are constructed every four sampling points, which is shown in Equation (18).The angle error of the sampling point before the four sampling points is calculated by this line.Then, the error compensation calculated from Equation ( 18) is obtained and stored in the internal memory unit of the single-chip microcomputer.
intercept term (18) where Mgd errT is the fitting error, and i k represents the sampling point.Therefore, the angle error of the magnetic encoder is corrected by searching for the compensation table saved in the internal memory unit of the microcontroller, when the encoder is working.Assuming that the current sampling point of angle value is θ x , its integer and decimal parts of it are where θ int and θ f loat are the integer and decimal parts of the angle value of the current sampling point, respectively, and τ represents the current sampling points.Therefore, the final angle that is compensated is Finally, the error table is obtained via the linear interpolation compensation algorithm using virtual cutting, which is shown in Figure 15a Therefore, the final angle that is compensated is Finally, the error table is obtained via the linear interpolation compensation rithm using virtual cutting, which is shown in Figure 15a,b is the noise distributi Figure 15a.Comparison with Figure 13 reveals that the high-frequency noise caus AD sampling is eliminated.

Experiment Analysis
The test device of the whole control system is presented in Figure 16.It is m composed of a magnetic encoder, a high-precision photoelectric encoder, controlle acquisition card, motor, and upper computer.An RX24T series R5F524TBAGFP manufactured by Renesas was selected to verify the effectiveness of the algorithm posed in this paper.This MCU supports 32-bit floating-point numbers and uses an receive data.

Experiment Analysis
The test device of the whole control system is presented in Figure 16.It is mainly composed of a magnetic encoder, a high-precision photoelectric encoder, controller, data acquisition card, motor, and upper computer.An RX24T series R5F524TBAGFP MCU manufactured by Renesas was selected to verify the effectiveness of the algorithm proposed in this paper.This MCU supports 32-bit floating-point numbers and uses an SPI to receive data.The main characteristic parameters of the PMSM are shown in Table 2.The data acquisition card is connected to the encoder in the motor control system.When the motor operates, the angle values of the encoder are sampled using the data acquisition card.The main characteristic parameters of the PMSM are shown Table 2.The data acquisition card is connected to the encoder in the motor control system.When the motor operates, the angle values of the encoder are sampled using the data acquisition card.

The Accuracy Test
The encoder is coaxial with the high-precision photoelectric encoder, and their angle values are output simultaneously.When the angle value of the photoelectric encoder with a resolution of 2 16 was set as a baseline, the angle error corrections of the magnetic encoder were completed by employing the method presented in this paper and the method in [26].The angle values of the two types of encoders were obtained, as shown in Figure 17.Meanwhile, Figure 18a,b displays the angle deviation.What remains clear is that the angle accuracy obtained with the method presented in this paper is ±200LSB (0-65,536 × 24LSB), which is significantly better than the one achieved by the arctangent cross-interval tabulation method, indicating that the accuracy of the magnetic encoder is improved effectively through linear interpolation compensation tabulation based on virtual cutting.

The Accuracy Test
The magnetic encoder is coaxial with the high-precision photoelectric encoder their angle values are output simultaneously.When the angle value of the photoel encoder with a resolution of 16 2 was set as a baseline, the angle error corrections magnetic encoder were completed by employing the method presented in this pape the method in [26].The angle values of the two types of encoders were obtained, as s in Figure 17.Meanwhile, Figure 18a,b displays the angle deviation.What remains cl that the angle accuracy obtained with the method presented in this paper is 200LS  65,536 × 24LSB), which is significantly better than the one achieved by the arcta cross-interval tabulation method, indicating that the accuracy of the magnetic enco improved effectively through linear interpolation compensation tabulation based o tual cutting.

The Resolution Test
An angle differential calculation was carried out to obtain the resolution of the netic encoder, as shown in Figure 19 What remains clear is that the resolution of the magnetic encoder obtained v proposed angle subdivision method is enhanced in this paper, compared with the fl ation in resolution of the single-pole magnetic encoder, which is exhibited in Figure

The Accuracy Test
The magnetic encoder is coaxial with the high-precision photoelectric encoder, and their angle values are output simultaneously.When the angle value of the photoelectric encoder with a resolution of 16 2 was set as a baseline, the angle error corrections of the magnetic encoder were completed by employing the method presented in this paper and the method in [26].The angle values of the two types of encoders were obtained, as shown in Figure 17.Meanwhile, Figure 18a,b displays the angle deviation.What remains clear is that the angle accuracy obtained with the method presented in this paper is 200LSB  (0-65,536 × 24LSB), which is significantly better than the one achieved by the arctangent cross-interval tabulation method, indicating that the accuracy of the magnetic encoder is improved effectively through linear interpolation compensation tabulation based on virtual cutting.

The Resolution Test
An angle differential calculation was carried out to obtain the resolution of the magnetic encoder, as shown in Figure 19 What remains clear is that the resolution of the magnetic encoder obtained via the proposed angle subdivision method is enhanced in this paper, compared with the fluctuation in resolution of the single-pole magnetic encoder, which is exhibited in Figure 19a,b.steel.It remains efficient and straightforward, and the issue of the existence jump points is effectively solved during the decoding process of multi-pole magnetic encoders.

Figure 3 .
Figure 3. (a) Angle value of the combined magnetic encoder.(b) Sorted angle value.
multi-pole angle value.The sorted angle resolution waveform is shown in Figure 3b.

Figure 3 .
Figure 3. (a) Angle value of the combined magnetic encoder.(b) Sorted angle value.

Figure 5 .
Figure 5. Pole number distribution of the three-layer window.

Sensors 2023 ,Figure 5 .
Figure 5. Pole number distribution of the three-layer window.

Figure 6 .
Figure 6.Two special cases.(a) case 1: p Fro act > p curr act , θ curr act ∈ S1.(b) case 2: p Bac act < p curr act , θ curr act ∈ S1. (p bac act , p curr act , p f ro act are the practical pole number of back-layer window, current window and frontlayer window).

Figure 7 .
Figure 7. Search process of window width based on IPSO.

Figure 7 .Figure 7 .
Figure 7. Search process of window width based on IPSO.

Figure 9 .
Figure 9. (a) State of initialized particle.(b) State of optimized particle.(where, I-VI represent unreasonable window widths as the single-increment try out method is used).

Figure 10 .
Figure 10.Final tabulation of the angle value interval and pole number.

Figure 10 .
Figure 10.Final tabulation of the angle value interval and pole number.

Figure 11 .
Figure 11.Flow chart of angle segmentation method based on IPSO.

Figure 11 .
Figure 11.Flow chart of angle segmentation method based on IPSO.

Figure 11 .
Figure 11.Flow chart of angle segmentation method based on IPSO.

Figure 13 .
Figure 13.Cross-interval tabulation method.(a) Table for deviation compensation between the magnetic encoder and photoelectric encoder.(b) Differential values of each point in (a).
of 1LSB for every 1LSB increase in the angle value.At the same time, ( ) p Ci is used to record the coordinates of the sampling point of the angle value for each stair C

Figure 13 .
Figure 13.Cross-interval tabulation method.(a) Table for deviation compensation between the magnetic encoder and photoelectric encoder.(b) Differential values of each point in (a).


is the average angle value of the magnetic encoder in every four st _ err aver  is the average angle error of the two types of encoders installed coaxially in ev four steps, and i is the sampling point.
,b is the noise distribution for Figure 15a.Comparison with Figure 13 reveals that the high-frequency noise caused by AD sampling is eliminated.where int  and float  are the integer and decimal parts of the angle value of the c sampling point, respectively, and  represents the current sampling points.

Figure 15 .
Figure 15.Linear interpolation compensation tabulation based on virtual cutting.(a) Deviatio pensation table for the magnetic encoder and photoelectric encoder.(b) Differential value point in (a).

Figure 15 .
Figure 15.Linear interpolation compensation tabulation based on virtual cutting.(a) Deviation compensation table for the magnetic encoder and photoelectric encoder.(b) Differential value of each point in (a).

Figure 16 .
Figure 16.Experimental platform of the control system.

Figure 16 .
Figure 16.Experimental platform of the control system.

Figure 18 .
Figure 18.Results of accuracy test.(a) Accuracy of the angle value obtained via the proposed m (b) Accuracy of the angle value acquired via cross-interval tabulation method.

Figure 17 .
Figure 17.Angle values of the two types of encoders.(a) Angle values of the two types of encoders obtained via cross-interval tabulation method and the method presented in this paper, respectively.(b) Enlarged view of (a).

Figure 18 .
Figure 18.Results of accuracy test.(a) Accuracy of the angle value obtained via the proposed method (b) Accuracy of the angle value acquired via cross-interval tabulation method.

Figure 18 .
Figure 18.Results of accuracy test.(a) Accuracy of the angle value obtained via the proposed method (b) Accuracy of the angle value acquired via cross-interval tabulation method.
Sensors 2023,23,x FOR PEER REVIEW 6 of 19according to the serial numbers and treated as a basis for the lookup table.The distribution of angle values after interval division is shown in Figure4.Interval of multi-pole angle value.Equation (4) shows the filter windows of the front, current and back layers, which are set to judge the number of poles.
window x  Therefore, the angle error of the magnetic encoder is corrected by searching for compensation table saved in the internal memory unit of the microcontroller, when encoder is working.Assuming that the current sampling point of angle value is k i represents the sampling point.x integer and decimal parts of it are

Table 2 .
The main characteristic parameters of the PMSM.

Table 2 .
The main characteristic parameters of the PMSM.